<template>
  <div>
    <!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商品等级" prop="productLevel">
        <el-select v-model="queryParams.productLevel" placeholder="请选择商品等级" clearable @keyup.enter.native="handleQuery">
          <el-option v-for="item in DictData.levelList" :key="item.value" :label="item.name" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商品名称" prop="goodName">
        <el-input v-model="queryParams.goodName" placeholder="请输入商品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="一级分类" prop="classOneId">
        <el-select v-model="queryParams.classOneId" placeholder="请选择一级分类" clearable @keyup.enter.native="handleQuery">
          <el-option v-for="item in classifyList" :key="item.value" :label="item.name" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否上架" prop="isInitiate">
        <el-select v-model="queryParams.isInitiate" placeholder="请选择是否上架" clearable @keyup.enter.native="handleQuery">
          <el-option label="上架" :value="1">
          </el-option>
          <el-option label="下架" :value="2">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form> -->

    <el-table v-loading="loading" :data="goodList" highlight-current-row>
      <el-table-column label="" align="center" prop="isCheck" width="50">
        <template slot-scope="{ row }">
          <el-checkbox
            v-model="row.isCheck"
            label=""
            :indeterminate="false"
            @change="checkChange(row)"
          ></el-checkbox>
        </template>
      </el-table-column>
      <el-table-column label="ID" align="center" prop="id" width="80" />
      <el-table-column label="商品名称" align="center" prop="goodName" />
      <el-table-column
        label="售价"
        align="center"
        prop="retailPrice"
        width="100"
      />
      <!-- <el-table-column
        label="商品库存"
        align="center"
        prop="goodInventory"
        width="100"
      /> -->
      <!-- <el-table-column
        label="是否上架"
        align="center"
        prop="isInitiate"
        width="100"
      >
        <template slot-scope="{ row }">
          {{ row.isInitiate == 1 ? "上架" : "下架" }}
        </template>
      </el-table-column> -->
    </el-table>

    <div class="foot">
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <div style="margin-top: 30px">
        <el-button
          type="primary"
          size="mini"
          @click="$emit('tableSelection', selectionList)"
          >确认</el-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import {
  listGood,
  getGood,
  delGood,
  addGood,
  updateGood,
  listGoodVo,
} from "@/api/system/goods/list";
import { forrmatterEnmu } from "@/utils/index";
export default {
  name: "Good",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供应商商品表格数据
      goodList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ifCloudGood: 0,
        classOneName: "热门复购",
      },
      // 表单参数
      form: {},
      classifyList: [],
      selectionList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    forrmatterEnmu,
    /** 查询供应商商品列表 */
    getList() {
      this.loading = true;
      listGoodVo(this.queryParams).then((response) => {
        this.goodList = response.rows.map((item) => {
          item.isCheck = false;
          return item;
        });
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
      };
      this.resetForm("form");
    },
    /**图片上传 */
    uploadImg(file) {
      this.form.goodImg = file;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    // handleSelectionChange(selection) {
    //   this.selectionList = selection
    //   this.ids = selection.map(item => item.id)
    //   this.single = selection.length !== 1
    //   this.multiple = !selection.length
    // },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商品";
    },

    // 设置单选
    checkChange(row) {
      this.goodList.forEach((item) => {
        if (item.id == row.id) {
          item.isCheck = true;
          this.selectionList.splice(0, 1, item);
        } else {
          item.isCheck = false;
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
.base-title {
  font-size: 18rpx;
  color: #1a1a1a;
  display: flex;
  align-items: center;
  margin-bottom: 15px;

  &::before {
    content: "";
    display: inline-block;
    width: 3px;
    height: 15px;
    background: #1777ff;
    border-radius: 3px;
    margin-right: 8px;
  }
}

::v-deep .pagination-container .el-pagination {
  position: static;
}

.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
